<template>
  <p><span class="allChose">
    <input type="checkbox" id="all" v-model="allDone"><span for="all">全选</span></span>
    <button style="width: 40px" @click="reverseChoose">反选</button>
  </p>
  <ul>
    <li v-for="item in planList" :key="item.id">
      <input type="checkbox" v-model="item.done"><span :class="{ haveDone:item.done }">{{ item.name }}</span>
    </li>
  </ul>
</template>

<script setup>
  import { ref, computed } from 'vue'
  const planList = ref([
    { id: 12, name: '跑步', done: false },
    { id: 76, name: '看书', done: false },
    { id: 31, name: '撸码', done: false },
    { id: 49, name: '追剧', done: false }
  ])
  const allDone = computed({
    get(){
      return planList.value.every(item => item.done)
    },
    set(val){
      planList.value.every(item => {
        item.done = val
        return true
      })
    }
  })
  function reverseChoose(){
      planList.value.every(item => {
        item.done = !item.done
        return true
      })
  }
</script>

<style>
  *{
    margin: 0;
    padding: 0;
  }
  #app{
    width: 300px;
    margin: 100px auto;
    padding: 10px 10px;
    background-color: rgb(207, 159, 207);
  }
  p{
    display: flex;
    justify-content: space-between;
    padding: 8px 6px;
    border-bottom: 1px solid #ccc;
    span{
      span{
        margin-left: 5px;
      }
    }
  }
  ul{
    li{
      display: flex;
      justify-content: space-between;
      list-style: none;
      padding: 8px 6px;
      border-bottom: 1px solid #ccc;
    }
  }
  .haveDone{
    color: #ddd;
    text-decoration: line-through;
  }
</style>